﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.dataAcess.sysDataSetTableAdapters;
using dhDataAcess.Model;
using dhDataAcess.linqDAL;

namespace dhDataAcess.sysDAL
{
   public  class queryMasterDAL
    {
        string tableName = "queryMaster";
          private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public queryMasterDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction;
            conn=_conn;
        }
      
        /// <summary>
        /// 插入一行查询表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>

        public int queryMasterInsert(queryMasterModel Row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string insertStr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();
           // string insertStr = "insert into accessGroup (groupNum,groupName,createDate,createUser,updateDate,updateUser,mark) values(@groupNum,@groupName,@createDate,@createUser,@updateDate,@updateUser,@mark)";
            SqlParameter[] para = {
                                        new SqlParameter ("@mark",Row .mark ),
                                        new SqlParameter ("@ceateUser",Row .ceateUser ),
                                        new SqlParameter ("@createDate",Row .createDate ),
                                        new SqlParameter ("@moduleNum",Row .moduleNum ),
                                        new SqlParameter ("@userNum",Row .userNum ),
                                        new SqlParameter ("@queryName",Row .queryName ),
                                        new SqlParameter ("@queryNum",Row .queryNum )
                                   };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }

        /// <summary>
        /// 更新一行查询表数据 
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>

        public int queryMasterUpdate(queryMasterModel Row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updateStr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
            //string updateStr = "update accessGroup set mark=@mark,updateUser=@updateUser,updateDate=@updateDate,createUser=@createUser,createDate=@createDate,groupName=@groupName where groupNum=@groupNum";
            SqlParameter[] para = {
                                        new SqlParameter ("@mark",Row .mark ),
                                        new SqlParameter ("@ceateUser",Row .ceateUser ),
                                        new SqlParameter ("@createDate",Row .createDate ),
                                        new SqlParameter ("@moduleNum",Row .moduleNum ),
                                        new SqlParameter ("@userNum",Row .userNum ),
                                        new SqlParameter ("@queryName",Row .queryName ),
                                        new SqlParameter ("@queryNum",Row .moduleNum)
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updateStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }


        /// <summary>
        /// 删除一行查询表数据
        /// </summary>
        /// <param name="groupNum"></param>
        /// <returns></returns>

        public int queryMasterDel(string queryNum)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deleteStr = baseBLL.dTableColumnRead.delSqlStr(tableName).ToString();
           // string deleteStr = "delete accessGroup where groupNum=@groupNum";
            SqlParameter[] para = {
                                        new SqlParameter ("@queryNum",queryNum)
                                   };

            cmd.Parameters.AddRange(para);
            cmd.CommandText = deleteStr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
